<template>
  <!--选择题库-->
  <view class="SelectQuestionPopup">
    <u-popup :show="isPopup" :round="15" mode="bottom" @close="onClose" safe-area-inset-bottom>
      <view class="title">请选择题库</view>
      <scroll-view
          scroll-y
          style="height: 60vh"
          lower-threshold="60"
          @scrolltolower="scrolltolower"
          class="list-wrapper"
      >
        <view class="list">
          <u-checkbox-group
              v-model="checkVals"
              placement="column"
              @change="checkboxChange"
          >
            <view v-for="(item,index) in list" :key="index" class="subject-item flex flex-row between">
              <view class="subject-item flex flex-row">
                <u-checkbox :name="item.subjectUuid" shape="circle" activeColor="#37B874" size="24"/>
                <view style="margin-left: 8px">{{ item.name }}</view>
              </view>
              <view class="fs_0" style="margin-left: 12px">{{ item.itemNum }}题</view>
            </view>
          </u-checkbox-group>
        </view>
      </scroll-view>
      <view class="footer">
        <view class="confirm btn" @click="confirm">确定</view>
        <view class="line"></view>
        <view class="close btn" @click="isPopup=false">取消</view>
      </view>
    </u-popup>
  </view>
</template>
<script>
import {pageSubject} from "@/myQuestionBank/services/myQuestionBankService";

export default {
  name: "SelectQuestionPopup",
  data() {
    return {
      isPopup: false,
      pageData:{
        queryKey:"",
        pageNo: 1,
        pageSize: 6,
        pageTotal:0
      },
      list: [],
      checkVals: []
    }
  },
  methods: {
    onClose() {
      this.isPopup = false;
      this.$emit("close")
    },
    async open(selectVals) {
      await this.getList()
      this.checkVals=selectVals
      this.isPopup = true;
    },
    getList() {
      pageSubject(this.pageData).then(res => {
        this.list = this.pageData.pageNo === 1 ? [...res.datas] : [...this.list, ...res.datas]
        this.pageData.pageTotal = res.totalPage
      })
    },
    checkboxChange(n) {
      /*console.log('change', n);
      console.log(this.checkVals)*/
    },
    confirm(){
      const list=this.list.filter(item=>this.checkVals.includes(item.subjectUuid))
      this.$emit("questionConfirm",list)
      this.isPopup = false;
    },
    scrolltolower(){
      console.log("分页")
      if(this.pageData.pageNo<this.pageData.pageTotal){
        this.pageData.pageNo++;
        this.getList()
      }
    }
  }
}
</script>
<style scoped lang="scss">
.SelectQuestionPopup {

  .title {
    color: #333333;
    font-size: 32rpx;
    font-weight: bold;
    margin-top: 32rpx;
    text-align: center;
  }

  .list-wrapper {
    border-bottom: solid 1px #EEEEEE;
    padding-bottom: 20px;
    .list{
      padding: 39px 22px 0 25px;
    }
    .subject-item {
      & + .subject-item {
        margin-top: 60rpx;
      }
    }

  }
  .btn{
    height: 96rpx;
    text-align: center;
    line-height: 96rpx;
    color: #000000;
    font-size: 14px;
  }
  .line{
    width: 100%;
    background-color: #F2F2F2;
    height: 6rpx;
  }
}
</style>